﻿Public Class frmNewCategory
    Dim Strsql As String
    Dim Mysql1 As New ClsSQLhelper
    Dim On_Load As Boolean = True
    Public Primary_Key As Integer
    Public Section_ID As Integer
    Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        Try
            If Me.Txtname.Text.Trim = "" Then Exit Sub
            If MsgBox("คุณต้องการบันทึกข้อมูลหรือไม่", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "ยืนยันการบันทึก") = MsgBoxResult.No Then Exit Sub

            Dim DT As New DataTable

            Strsql = "Select * from category where category_name= '" & Me.Txtname.Text & "'  and sectionid = " & Section_ID

            DT = Mysql1.GetMYSQLDataTable(Strsql, "Category")
            If DT.Rows.Count <> 0 Then
                MsgBox("Category นี้มีอยู่แล้วไม่สามารถบันทึกซ้ำได้อีก", MsgBoxStyle.Critical)
                Exit Sub
            End If
            Strsql = "Insert into category (category_name,note,sectionid,active) values ('" & Me.Txtname.Text & "', '" & Me.TxtNote.Text & "'," & Section_ID & "," & IIf(Me.ChkActive.Checked = True, 1, 0) & ")"

            Mysql1.MySQLExecute(Strsql)
            DialogResult = Windows.Forms.DialogResult.OK
            MsgBox("เพิ่มข้อมูลเข้าเรียบร้อยแล้ว", MsgBoxStyle.Information)



        Catch ex As Exception
            With frmDebug
                .lblFormName.Text = Me.Name
                .lblFunctionName.Text = "BtnSave_Click"
                .MemoErr_Description.Text = ex.Message
                .MemoSQL.Text = Strsql
                .ShowDialog()
            End With
        End Try
    End Sub

    Private Sub frmNewCategory_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
        Me.Dispose()
    End Sub


End Class